package fregat.microchip.usb.device;

import fregat.microchip.usb.device.register;

public class timer1 implements register {
	public enum prescaler {
		_1_8 ((byte)0x3),
		_1_4 ((byte)0x2),
		_1_2 ((byte)0x1),
		_1_1 ((byte)0x0);
		private byte value;
		prescaler (byte b)
		{
			value = b;
		}
		public byte toByte ()
		{
			return (byte) (value << 4);
		}
	};
	
	private boolean 	_16bit_operation;
	private boolean 	t1run;
	private prescaler	presc;
	private boolean		t1oscen;
	private boolean		t1sync;
	private boolean		tmr1cs;
	private boolean		tmr1on;
	
	private int			buffer;
	
	public timer1 ()
	{
		_16bit_operation 	= true;
		t1run 				= false;
		presc				= prescaler._1_1;
		t1oscen 			= false;
		t1sync				= false;
		tmr1cs				= false;
		tmr1on				= false;
	}
	
	public byte toByte ()
	{
		byte b = 0x0;
		b |= b & (byte)0x7f | (_16bit_operation?0x80:0x0);
		b |= b & (byte)0xbf;
		b |= b & (byte)0xcf | (presc.toByte() & 0x30);
		b |= b & (byte)0xf7 | (t1oscen?0x8:0x0);
		b |= b & (byte)0xfb | (t1sync?0x4:0x0);
		b |= b & (byte)0xfd | (tmr1cs?0x2:0x0);
		b |= b & (byte)0xfe | (tmr1on?0x1:0x0);
		return b;
	}
	
	public void enable ()
	{
		tmr1on = true;
	}
	
	public void disable ()
	{
		tmr1on = false;
	}
	
	public void setPrescaler (prescaler p)
	{
		presc = p;
	}
	
	public void setBuffer (int buf)
	{
		buffer = buf;
	}
	
	public int getBuffer ()
	{
		return buffer;
	}
}
